using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDF.Data;
using DDF.Data.Providers;
using System.Data;
using System.Linq.Expressions;
using System.Configuration;
using ARR.Entities.Gateways;

namespace ARR.DataModel.Repositories
{
	public static partial class TempArticleSalesSummaryRepository
	{
		private static string connString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
		
		public class TempArticleSalesSummaryDbo : DatabaseObject
        {
            public TempArticleSalesSummaryDbo()
            {
                Name = "TempArticleSalesSummary";
                GeneratedClassName = "TempArticleSalesSummary";
                SequenceName = "N/A";
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Articles", ColumnType = "int", IsIdentity = false, IsNullable = true, Length = 4, Precision = 10, Scale = 0, GeneratedPropertyName = "Articles" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Stores", ColumnType = "int", IsIdentity = false, IsNullable = true, Length = 4, Precision = 10, Scale = 0, GeneratedPropertyName = "Stores" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Dates", ColumnType = "int", IsIdentity = false, IsNullable = true, Length = 4, Precision = 10, Scale = 0, GeneratedPropertyName = "Dates" });
              
            }
        }
		
		public static List<TempArticleSalesSummaryRow> Select(Expression<Func<TempArticleSalesSummaryRow, bool>> expression)
        {
            List<TempArticleSalesSummaryRow> rows = new List<TempArticleSalesSummaryRow>();

            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                IDataReader reader = database.Select<TempArticleSalesSummaryRow>(new TempArticleSalesSummaryDbo(), expression);

                Load(reader, rows);
            }

            return rows;
        }
		
		public static List<TempArticleSalesSummaryRow> Select()
		{
			List<TempArticleSalesSummaryRow> rows = new List<TempArticleSalesSummaryRow>();

			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.Select<TempArticleSalesSummaryRow>(new TempArticleSalesSummaryDbo(), null);

				Load(reader, rows);
			}

			return rows;
		}
		
		public static List<TempArticleSalesSummaryRow> PagedSelect(Expression<Func<TempArticleSalesSummaryRow, bool>> filterExpression, Expression<Func<TempArticleSalesSummaryRow, object>> orderByExpression, int pageNumber, int pageSize)
		{
			List<TempArticleSalesSummaryRow> rows = new List<TempArticleSalesSummaryRow>();
			
			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.PagedSelect<TempArticleSalesSummaryRow>(new TempArticleSalesSummaryDbo(), filterExpression, orderByExpression, pageNumber, pageSize);

				Load(reader, rows);
			}

			return rows;
		}
		
		private static void Load(IDataReader reader, List<TempArticleSalesSummaryRow> TempArticleSalesSummaryList)
        {
            TempArticleSalesSummaryRow row;

            while (reader.Read())
            {
                row = new TempArticleSalesSummaryRow()
                {
					Articles = Util.CastDbValue<int?>(reader["Articles"]),
					Stores = Util.CastDbValue<int?>(reader["Stores"]),
					Dates = Util.CastDbValue<int?>(reader["Dates"])
                };
                                
                TempArticleSalesSummaryList.Add(row);
            }

            reader.Close();
        }

		
		
		
	}
}
	
